package com.yjhb.android.sbz.activity

import android.content.Intent
import android.graphics.Color
import android.view.View
import com.jojo.android.zxlib.base.mvp.BasePresenter
import com.jojo.android.zxlib.tool.Global
import com.yjhb.android.sbz.R
import com.yjhb.android.sbz.tool.DataSaveTool
import com.yjhb.android.sbz.v2.dialog.PrivacyDialog
import kotlinx.android.synthetic.main.activity_splash.*
import pl.droidsonroids.gif.GifDrawable


/**
 *  创建者 zx
 *  创建时间 2021/3/16 18:58
 */
class SplashActivity2 : BaseActivity<BasePresenter<*, *>>() {

    override fun initPresenter(): BasePresenter<*, *>? {
        return null
    }

    override fun getLayoutId() = R.layout.activity_splash

    override fun initUI() {
        if (!this.isTaskRoot) {
            finish()
            return
        }
        window.decorView.systemUiVisibility =
            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        window.statusBarColor = Color.TRANSPARENT

        //先延时1s后再播放动画
        Global.getInstance().mainHandler.postDelayed({

            gifView.setImageResource(R.mipmap.lanuch)
            gifView.setFreezesAnimation(false)
            val gifDrawable = gifView.drawable as GifDrawable
            gifDrawable.loopCount = 1;
            gifDrawable.addAnimationListener {
                if (DataSaveTool.isShowPrivacyTips()) {
                    val dialog = PrivacyDialog(this)
                    dialog.show()
                } else {
                    startActivity(Intent(activity, MainActivity::class.java))
                    finish()
                }
            }
            bgView.visibility = View.GONE
            gifDrawable.start()
        }, 1000)


    }

    override fun onDestroy() {
        super.onDestroy()
    }

    override fun initData() {
    }

    override fun regEvent() {
    }
}